package com.springboot.controller;

import com.springboot.model.OrderForm;
import com.springboot.model.PatientInfoForm;
import com.springboot.model.UserLoginForm;
import com.springboot.service.DoctorCheckDiseaseAtPatientListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;

/**
 * 本控制台用于医生在患者列表界面查看病情详情
 * 返回病情名称 疾病等级 检查结果 注意事项
 */
@Controller
public class DoctorCheckDiseaseAtPatientListController {
    @Autowired
    DoctorCheckDiseaseAtPatientListService doctorCheckDiseaseAtPatientListService;
    /**
     * 医生在患者列表界面查看病情
     */
    @CrossOrigin
    @RequestMapping(value = "/getIllRecord")
    public @ResponseBody
    String doctorGetAllRecord(@RequestParam("doctorTel") String doctorTel,
                              @RequestParam("patientTel") String patientTel,
                              @RequestParam("orderDate") String orderDate,
                              @RequestParam("orderTime") String orderTime) {
        System.out.println("医生在患者列表查看病情");
        try {
            UserLoginForm doctor=doctorCheckDiseaseAtPatientListService.findUserByTel(doctorTel);
            UserLoginForm patient=doctorCheckDiseaseAtPatientListService.findUserByTel(patientTel);
            int doctorId=doctor.getUserId();
            int patientId=patient.getUserId();
            OrderForm orderForm=new OrderForm();
            orderForm.setDoctorId(doctorId);
            orderForm.setPatientId(patientId);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");//日期格式
            java.util.Date d = null;
            try {
                d = format.parse(orderDate);
            } catch (Exception e) {
                e.printStackTrace();
            }
            java.sql.Date date = new java.sql.Date(d.getTime());
            orderForm.setBootDate(date);
            orderForm.setBootTime(orderTime);
            OrderForm order=doctorCheckDiseaseAtPatientListService.findBookIdByOrder(orderForm);
            int bookId=order.getBootId();
            System.out.println("预约id："+bookId);
            PatientInfoForm patientInfoForm=doctorCheckDiseaseAtPatientListService.findPatientInfoByBookId(bookId);
            System.out.println(patientInfoForm.toString());
            return patientInfoForm.toString1();
        } catch (Exception e) {
            return "False";
        }
    }
}